package oj;

public class LC86 {
    public ListNode partition(ListNode head, int x) {
        if(head==null || head.next==null) return head;
        ListNode small=new ListNode(-1);
        ListNode smallHead=small;
        ListNode large=new ListNode(-1);
        ListNode largeHead=large;
        while(head!=null){
            if(head.val<x){
                small.next=head;
                small=small.next;
            }else{
                large.next=head;
                large=large.next;
            }
            head=head.next;
        }
        large.next=null;
        small.next=largeHead.next;
        return smallHead.next;
    }
}
